﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace CustomPanelDemo01
{
    /// <summary>
    /// 这样的代码 在外面加scrollview 是不会有滚动的效果的   因为MeasureOverride直接把页面中显示的返回
    /// </summary>
    public class MyPanel01 : Panel
    {
        /// <summary>
        /// 测量
        /// </summary>
        /// <param name="availableSize"></param>
        /// <returns></returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            foreach (UIElement item in InternalChildren)
            {
                item.Measure(availableSize);
            }
            return availableSize;
        }

        /// <summary>
        /// 排列
        /// </summary>
        /// <param name="finalSize"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            double offset_y = 0;
            foreach (UIElement item in InternalChildren)
            {
                item.Arrange(new Rect(0, offset_y, finalSize.Width, item.DesiredSize.Height)); 
                offset_y += item.DesiredSize.Height;
            }
            return base.ArrangeOverride(finalSize);
        }
    }
}
